package com.hzhr.iot.collect.constant.entity.constant;


import com.hzhr.iot.collect.constant.entity.MessagetmpEntity;

import java.util.HashMap;
import java.util.Map;

public class MessagetmpEntityConstant {
	public static Map<Integer, MessagetmpEntity> MAP = new HashMap<Integer, MessagetmpEntity>() {
		private static final long serialVersionUID = 1L;

		{
			putAll(getEntityMap(getEntity(1, 1, 7, 7, 1, 8, 9, 10, 11, 1, 23, 0)));
			putAll(getEntityMap(getEntity(2, 2, 6, 7, 1, 8, null, 10, 11, 1, 23, 2)));
			putAll(getEntityMap(getEntity(3, 3, 4, 7, 2, null, null, 10, 178, 1, 13, 0)));
			putAll(getEntityMap(getEntity(4, 4, 6, 374, 1, 8, null, 10, 11, 1, 23, 2)));

		}
	};


	public static MessagetmpEntity getMessagetmpEntityByProtocolId(Integer protocolId) {
		if (protocolId == null) return null;
		Map<Integer, MessagetmpEntity> map = MAP;
		for (Map.Entry<Integer, MessagetmpEntity> entry : map.entrySet()) {
			MessagetmpEntity messagetmpEntity = entry.getValue();
			if (protocolId.equals(messagetmpEntity.getProtocolId())) return messagetmpEntity;
		}
		return null;
	}
	
	private static MessagetmpEntity getEntity(Integer id, Integer protocolId, Integer fieldsizesum, Integer startcodefieldId,
			Integer messageheadtempId, Integer dataareasizefieldId, Integer encryptedbytefieldId, Integer crcfieldId,
			Integer endcodefieldId, Integer messageheadstartindex, Integer dataareastartindex, Integer reverseMode) {
		MessagetmpEntity messagetmpEntity = new MessagetmpEntity();
		messagetmpEntity.setId(id);
		messagetmpEntity.setProtocolId(protocolId);
		messagetmpEntity.setFieldsizesum(fieldsizesum);
		messagetmpEntity.setStartcodefieldId(startcodefieldId);
		messagetmpEntity.setMessageheadtempId(messageheadtempId);
		messagetmpEntity.setDataareasizefieldId(dataareasizefieldId);
		messagetmpEntity.setEncryptedbytefieldId(encryptedbytefieldId);
		messagetmpEntity.setCrcfieldId(crcfieldId);
		messagetmpEntity.setEndcodefieldId(endcodefieldId);
		messagetmpEntity.setMessageheadstartindex(messageheadstartindex);
		messagetmpEntity.setDataareastartindex(dataareastartindex);
		messagetmpEntity.setReverseMode(reverseMode);
		return messagetmpEntity;
	}
	
	private static Map<Integer, MessagetmpEntity> getEntityMap(MessagetmpEntity messagefieldEntity) {
		Map<Integer, MessagetmpEntity> map = new HashMap<>();
		map.put(messagefieldEntity.getId(), messagefieldEntity);
		return map;
	}
}
